package com.example.understand_compose1.testcase_activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import com.example.understand_compose1.R

class FetQQLoginActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.qq_login_layouttest)

        val ed_username: EditText = this.findViewById(R.id.qq_login_username)
        val ed_password: EditText = this.findViewById(R.id.qq_login_password)
        val btn_login: Button = this.findViewById(R.id.login_btn)

        // 处理登录按钮逻辑
        btn_login.setOnClickListener {
//            测试用，没必要每点击都展示
//            if (it != null) {
//                Toast.makeText(it.context, "登录按钮被点击了", Toast.LENGTH_SHORT).show()
//            }
            val validUsername: String = ed_username.text.toString().trim()
            val validPassword: String = ed_password.text.toString().trim()
            if (TextUtils.isEmpty(validUsername) or TextUtils.isEmpty(validPassword)) {
                Toast.makeText(it.context, "输入的账号或密码为空", Toast.LENGTH_SHORT).show()
            }

//            if (TextUtils.isEmpty(validPassword)) {
//                Toast.makeText(it.context, "输入的密码为空", Toast.LENGTH_SHORT).show()
//            }

            if (validUsername.isNotEmpty() and validPassword.isNotEmpty()) {
                Toast.makeText(it.context, "默认登录成功$validUsername/$validPassword", Toast.LENGTH_SHORT).show()
                // 有了密码和账号以后，我们需要新的意图和页面去跳转
                // 跳转到Fet3Activity
                val toFet3Intent: Intent = Intent(this, FetIntentGetValueActivity::class.java)
                // 将值储存在intent中
                toFet3Intent.putExtra("account", validUsername)
                toFet3Intent.putExtra("password", validPassword)
                startActivity(toFet3Intent)
            }
        }
    }
}